{% include 'Dockerfile.base.j2' %}

{% if disable_cache_mounts %}
RUN \
{% else %}
RUN --mount=type=cache,target=/var/cache/apt \
{% endif %}
    apt-get -y install --no-install-recommends \
    {% for dependency in apt_dependencies %}
        {% if not loop.last %}
        {{ dependency }} \
        {% else %}
        {{ dependency }}
        {% endif %}
    {% endfor %}

WORKDIR /usr/src/app

# @TODO: WiFi Connect 4.11.1 doesn't have a release for Raspberry Pi
#        devices that has ARMv6 support. We should remove this once a
#        new compatible release is available.
RUN if [[ ! -z "{{ archive_url }}" ]]; then \
    curl -sL -o /tmp/wifi_connect.zip "{{ archive_url }}" && \
    unzip -o /tmp/wifi_connect.zip -d /usr/src/app && \
    rm /tmp/wifi_connect.zip; fi

COPY requirements/requirements.wifi-connect.txt /tmp/requirements.txt
{% if disable_cache_mounts %}
RUN \
{% else %}
RUN --mount=type=cache,target=/root/.cache/pip \
{% endif %}
    pip3 install -r /tmp/requirements.txt --break-system-packages

COPY send_zmq_message.py ./

RUN touch /var/lib/misc/dnsmasq.leases

COPY bin/start_wifi_connect.sh ./

ENV DEVICE_TYPE={{ board }}
ENV GIT_HASH={{ git_hash }}
ENV GIT_SHORT_HASH={{ git_short_hash }}
ENV GIT_BRANCH={{ git_branch }}

CMD ["bash", "start_wifi_connect.sh"]
